<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/10/12
 * Time: 8:48
 */

namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use app\portal\service\PostService;
use app\portal\model\PortalPostModel;
use think\Db;

class NewController extends HomeBaseController
{
    //文章列表
    public function index(){

        if(request()->isAjax()){
            $type_id=input('type_id');
            $list=get_list($type_id);
            return json(['list'=>$list,'page'=>$list->render()]);
        }else{
            $list_1 = get_list(9);
            $list_2 = get_list(10);
            $this->assign('list_1', $list_1);
            $this->assign('list_2', $list_2);
            return $this->fetch(':news');
        }

    }
    //文章详情
        public function detail()
        {
            $id=input('id');
            $model = new PortalPostModel();
            $data=$model->with('user')->find($id);
            $this->assign('data',$data);
            return $this->fetch(':newDetail');
        }


//    public function detail(){
//        $portalCategoryModel = new PortalCategoryModel();
//        $postService         = new PostService();
//
//        $articleId  = $this->request->param('id', 0, 'intval');
//        $categoryId = $this->request->param('cid', 0, 'intval');
//        $article    = $postService->publishedArticle($articleId, $categoryId);
//
//        if (empty($article)) {
//            abort(404, '文章不存在!');
//        }
//
//
//        $prevArticle = $postService->publishedPrevArticle($articleId, $categoryId);
//        $nextArticle = $postService->publishedNextArticle($articleId, $categoryId);
//
//        $tplName = 'article';
//
//        if (empty($categoryId)) {
//            $categories = $article['categories'];
//
//            if (count($categories) > 0) {
//                $this->assign('category', $categories[0]);
//            } else {
//                abort(404, '文章未指定分类!');
//            }
//
//        } else {
//            $category = $portalCategoryModel->where('id', $categoryId)->where('status', 1)->find();
//
//            if (empty($category)) {
//                abort(404, '文章不存在!');
//            }
//
//            $this->assign('category', $category);
//
//            $tplName = empty($category["one_tpl"]) ? $tplName : $category["one_tpl"];
//        }
//
//        Db::name('portal_post')->where('id', $articleId)->setInc('post_hits');
//
//
//        hook('portal_before_assign_article', $article);
//
//        $this->assign('article', $article);
//        $this->assign('prev_article', $prevArticle);
//        $this->assign('next_article', $nextArticle);
//
//        $tplName = empty($article['more']['template']) ? $tplName : $article['more']['template'];
//
//        return $this->fetch("/$tplName");
//    }

}